//
//  BaseService.h
//  Stock
//
//  Created by blacksun on 11-6-9.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
#import "CommonUtil.h"
#import "SQLiteInstanceManager.h"
#import "MacroDefine.h"

@protocol ServiceDelegate
-(void)requestFinishedWithResult:(id)aResult andUserinfo:(NSDictionary *)aUserinfo;
-(void)requestFinishedwithError:(NSError *)aError andUserinfo:(NSDictionary *)aUserinfo;
@end

@interface BaseService : NSObject<ASIHTTPRequestDelegate> {
    NSMutableArray *workingRequests;
    id<ServiceDelegate> delegate;
    NSOperationQueue *operationQueue;
}
@property(nonatomic, retain) NSMutableArray *workingRequests;
@property(nonatomic, assign) id<ServiceDelegate> delegate;
@property(nonatomic, retain) NSOperationQueue *operationQueue;

-(id)initWithDelegate:(id<ServiceDelegate>)aDelegate;

#pragma mark -database operation;
-(void) batchSaveObjects:(NSArray *)models;
-(void) batchAndAsynchronousSaveObjects:(NSArray *)models;
-(NSInteger)countWithTableName:(NSString *)tableName andCriteriaString:(NSString *)criteriaString;

#pragma mark -cancle request
-(void)cancleAllRequest;
-(void)cancleRequest:(ASIHTTPRequest *)aRequest;
@end
